const express = require("express");
const router = express.Router();
const service = require("../model/user");

router.post("/add", (req, res) => {
    service.add(
        req.body.account,
        req.body.pwd,
        req.body.name,
        req.body.avatar,
        data => {
            res.send(data)
                .status(200)
                .end();
            console.log("创建了一个user: " + req.body.name);
        }
    );
});

router.post("/login", (req, res) => {
    service.login(req.body.account, req.body.pwd, data => {
        res.send(data)
            .status(200)
            .end();
        console.log("登录了一个user: " + req.body.account);
    });
});

router.post("/test", (req, res) => {
    service.test(req.body.account, req.body.token, data => {
        res.send(data)
            .status(200)
            .end();
        // console.log("测试了一个user的token: " + );
    });
});

router.post("/find", (req, res) => {
    service.findById(req.body.id, data => {
        res.send(data)
            .status(200)
            .end();
    });
});

router.get("/all", (req, res) => {
    service.getAll(data => {
        res.send(data)
            .status(200)
            .end();
    });
});

module.exports = router;
